import { Component, OnInit } from '@angular/core';
import { NewUserGroupService} from './new-user-group.service';
import {Router} from "@angular/router";
import { Response} from '@angular/http';
import {GlobalService} from "../../../global.service";

@Component({
  selector: 'app-new-user-group',
  templateUrl: './new-user-group.component.html',
  styleUrls: ['./new-user-group.component.css']
})
export class NewUserGroupComponent implements OnInit {


  data:UserGroupsInfo = new UserGroupsInfo;

  constructor(
    private globalService:GlobalService,
    private newUserGroupService:NewUserGroupService,
    private router:Router,
  ) { }

  ngOnInit() {
      this.data.creator=this.globalService.getCurrentUser().code;
  }

  save(){
    this.data.properties.save = true;
    this.newUserGroupService.saveUserGroupInfo(this.data).subscribe((res:Response)=>{
      console.log(res.json());
      if(res.json().success){
        this.router.navigateByUrl("/user/userGroups")
      }else {
        alert(res.json().msg);
      }
    });
  }
}

class UserGroupsInfo{
  name:string;
  remark:string;//描述
  creator:string;
  properties:Properties = new Properties;
}
class Properties {
  save:any;
}
